using System;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using IWin32Window = System.Windows.Forms.IWin32Window;

namespace RandomSearch.ClientUi {
    public static class WpfExtensions {
        public static IWin32Window GetIWin32Window(this Visual visual) {
            var source = PresentationSource.FromVisual(visual) as HwndSource;
            IWin32Window win = new OldWindow(source.Handle);
            return win;
        }

        #region Nested type: OldWindow

        private class OldWindow : IWin32Window {
            private readonly IntPtr _handle;

            public OldWindow(IntPtr handle) {
                _handle = handle;
            }

            #region IWin32Window Members

            IntPtr IWin32Window.Handle {
                get { return _handle; }
            }

            #endregion
        }

        #endregion
    }
}